<?php

include 'career.php';

/**
 * Description of SolicitudCursosData
 *
 * @author ETorres
 */
class SolicitudCursosData extends ModuleModel {
    const tabla = "acaweb_solicitudes_cursos";

    /**
     *
     * @var Query
     */
    private $query;

    function __construct() {
        parent::__construct();
        $this->query = ModulesContext::instance()->getQueryFactory()->getQuery();
    }

    function crear($datos) {
        return $this->query->insertInto(self::tabla)
                        ->set("docente", $datos["docente"])
                        ->set("email", $datos["email"])
                        ->set("codigoCurso", $datos["codigoCurso"])
                        ->set("nombreCurso", $datos["nombreCurso"])
                        ->set("resumenCurso", $datos["resumenCurso"])
                        ->set("idPrograma", $datos["idPrograma"])
                        ->set("estado", "1")
                        ->set("fechaCreacion", date("d/m/Y"))
                        ->commit(true);
    }

    function getAll() {
        $result = $this->query->select()
                ->from(array(self::tabla))
                ->where("estado", '1')
                ->orWhere("estado", '2')
                ->get();

        $solicitudes = $result->resultList();
        $solicitudesMapped = array();
        
        foreach ($solicitudes as $solicitud){
            $solicitud['idPrograma'] = career::GetById($solicitud['idPrograma'])->getNombrePlan();
            array_push($solicitudesMapped, $solicitud);
        }
        
        return $solicitudesMapped;
        
    }

    function GetById($id) {
        $result = $this->query->select()
                ->from(array(self::tabla))
                ->where("id", $id)
                ->get();

        return $result->firstRow();
    }
    
    function delete($id) {
        $result = $this->query->delete(self::tabla)
                ->where("id", $id)
                ->commit();

        return $result;
    }
    
    function cambiarEstado($id, $estado) {
        $result = $this->query->update(self::tabla)
                ->where("id", $id)
                ->set("estado", $estado)
                ->commit();

        return $result;
    }

}

?>
